<template>
  <div>
    <div class="header">
      <p class="title">待办事项</p>
      <input class="new-todo" type="text" placeholder="请填写代办任务" v-model.trim="name" @keyup.enter="enterName"/>
    </div>
  </div>
</template>

<script setup>
import { ref, defineEmits } from 'vue'
const name = ref('')
const emit = defineEmits(['addTodo']);

const enterName = () => { 
  if(name.value.trim() === ''){
    alert('请输入内容')
    return
  }
  emit('addTodo', name.value)
  name.value = ''
}
</script>

<style scoped>
.header {
  margin: 0;
  padding: 0;
  width: 100%;

  position: relative;
}

.title {
  margin: 0;
  width: 100%;
  text-align: center;
  font-size: 50px;
  font-family: 宋体;
  color: #c93030;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.new-todo {
  margin-top: 2px;
  width: 94%; /* 占据 header 的全部宽度 */
  height: 80px;
  border: none;
  padding-left: 80px; /* 文本距离左边 80px */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.new-todo:focus{
  outline: none;
}
</style>